package com.dys.designpattern.singleton.applicationscenarios;

/**
 * @author 田建松
 * @version V1.0.0
 * @description 2.单例模式-静态内部类实现生成序列号
 * @date 2024/5/10
 * @since 1.0
 */
public class SerialGenerator_InnerClass {

    private long code;
    private SerialGenerator_InnerClass(){}

    public synchronized long  next() {
        return ++code;
    }
    private static class InnerClass{
        final static SerialGenerator_InnerClass instance = new SerialGenerator_InnerClass();
    }

    public static SerialGenerator_InnerClass getInstance() {
        return InnerClass.instance;
    }
}
